<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .bg {
        color: red;
    }
</style>

<body>
    <div id="app">
        <div v-for="(item,index) in arr" @click="a(item),item.active = true" :class="{'bg': item.active}">
            <span>{{ item.type }}</span>
        </div>
        <div v-for="(item,index) in i">{{ item.type }}
            <button @click="i[index].active = false,i.splice(index,1)">删除</button>
        </div>

    </div>
</body>
<script src="./vue.js"></script>
<script>
    const { createApp, ref, reactive } = Vue
    createApp({
        setup() {
            let arr = reactive([{
                type: 1,
                active: false
            }, {
                type: 2,
                active: false
            }, {
                type: 3,
                active: false
            }, {
                type: 4,
                active: false
            }])
            let i = ref([])

            const a = (item) => {
                if (!i.value.includes(item)) {
                    i.value.push(item);
                }
            }

            return {
                arr,
                i,
                a
            }
        }
    }).mount("#app")
</script>

</html>